<?php

namespace App\Api\V1\Controllers;

use App\Exceptions\ApiException;
use App\Models\JpushMobile;
use App\Services\UserService;

/**
 * 用户中心
 * Class UserController
 * @package App\Api\V1\Controllers
 */
class JpushController extends CommonController
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 存储registration_id
     * @return array
     */
    public function setRegistrationId()
    {
        $registration_id = IT('registration_id', true, '缺少参数', 10011);
        $mobile_unique_code = IT('mobile_unique_code', true, '缺少参数', 10011);
        $pushChannel = IT('push_channel', 1);
        $ticket = IT('ticket');
        $client_source = IT('ClientSource');

        $saveJpush = JpushMobile::saveJpush(['mobile_unique_code'=>$mobile_unique_code, 'registration_id'=>$registration_id, 'push_channel'=>$pushChannel]);
        if(!$saveJpush)
            return json_error('存储设备标识失败',[],10069);

        $bind = UserService::bindPushChannel($ticket, $client_source, $registration_id);

        return json_success('ok',[],10000);
    }

}